import React, { useEffect, useState } from 'react';
import { Modal, Form, Space, notification } from 'antd';
import FormCondition from '@/components/FormCondition';
import { connect, history } from 'umi';
import { Button, Row, Col } from 'antd';

const CheckOrderForm = (props) => {
  const { visible = false, onClose, loading, dispatch, handleCallback, cleanSelect } = props;
  const { show = false, detail = {}, selectIdList = [] } = visible;
  const { } = detail;
  const [params, setParams] = useState({
    assignAdminFlag: '0'
  })
  const { assignAdminFlag, status } = params
  const [list, setList] = useState([])
  const [form] = Form.useForm();
  // 确认提交
  const [organizationAuthAdminList, setAuthAdminList] = useState([])
  console.log(params)
  const handleUpAudit = () => {
    form.validateFields().then((values) => {
      const { assignAdminIds, assignAdminFlag } = values
      dispatch({
        type: 'promoter/fakeCheckApplyPromoter', payload: {
          ...values,
          idList: selectIdList,
          assignAdminIds: assignAdminFlag === '1' ? assignAdminIds.toString() : ''
        }, callback: () => {
          cleanSelect();
          handleCallback()
          onClose()
        }
      })

    });
  };
  useEffect(() => {
    dispatch({
      type: 'weCom/fetchSearchAdminAll',
      payload: {
        page: 1,
        limit: 9999,
        status: '1'
      },
      callback: (e) => {
        setAuthAdminList(e)
      }
    });
  }, [])
  useEffect(() => {
    if (!show) {
      setList([])
      setParams({
        assignAdminFlag: '0'
      })
    }
  }, [show])
  const formItems = [
    {
      label: `审核状态`,
      name: 'status',
      type: 'select',
      onChange: (e) => {
        setParams({
          ...params,
          assignAdminFlag: '0',
          status: e
        })
        form.setFieldValue('assignAdminFlag', '0')

      },
      style: { textAlign: 'left' },
      select: {
        1: '通过审核',
        2: '拒绝审核'
      },
    },
    {
      label: `备注`,
      name: 'checkRemark',
      type: 'textArea',
      rules: [{ required: false }],
    },
    {
      visible: status === '1',
      label: '是否绑定员工',
      name: 'assignAdminFlag',
      onChange: (e) => {
        setList([])
        setParams({
          ...params,
          assignAdminFlag: e.target.value
        })
      },
      type: 'radio',
      select: {
        0: '否',
        1: '是',
      },
    },
    {
      visible: assignAdminFlag === '1' && status === '1',
      label: '员工选择',
      name: 'assignAdminIds',
      type: 'select',
      mode: 'multiple',
      select: organizationAuthAdminList,
      fieldNames: { label: 'username', value: 'id' },
    },
  ];
  const formItemLayout = {
    labelCol: {
      sm: { span: 3 },
    },
    wrapperCol: {
      sm: { span: 0 },
    },
  };
  const modalProps = {
    title: '审核申请',
    width: 900,
    visible: show,
    maskClosable: true,
    destroyOnClose: true,
    zIndex: 1001,
    confirmLoading: loading,
  };

  return (
    <Modal {...modalProps} onCancel={onClose} onOk={handleUpAudit}>
      <Space direction={'vertical'} style={{ display: 'flex', textAlign: 'left', justifyContent: 'flex-start', width: '100%' }}>
        <FormCondition formItemLayouts={formItemLayout} initialValues={{ assignAdminFlag: '0' }} form={form} formItems={formItems}></FormCondition>
      </Space>

    </Modal >
  );
};

export default connect(({ order, loading }) => ({
  loading: loading.effects['promoter/fakeCheckApplyPromoter'],
}))(CheckOrderForm);
;
